package com.zl.smartmall.library.po;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class ProductDetailInfo {

	private double originalCost;// 商品吊牌价，灰色的价格，市场价
	private double currentCost;// 售价
	private double marketCost;//市场价
	private int saleNum;// 销售量(历史总销量)或月销售量
	private int inventoryNum;// 库存量，目前没有用到
	private int shopId;// 商店id，为以后预留的
	private int productId;// 商品id，
	private int commentsCount;//评价数
	private int gold;
	private double goldToMoneyRatio;//抵扣率
	private double goldToMoney;//金豆抵扣的钱
	private String deliveryUrl;
	private String productTitle;// 商品标题
	private String productName;// 产品名称
	private String productIntros;// 产品简单文字介绍
	private String shopName;// 商店名称
	private String openTime;//营业时间
	private int msendtime;//限时秒杀时间
	private List<String> labels = new ArrayList<String>();
	private List<PictureInfo> productPictures;
	private List<Map<String, String>> specifications = new ArrayList<Map<String,String>>();// 产品规格说明，有不定数量个
	private List<ProductDetailGraphicDetailInfo> graphicDetails;
	private List<ProductEvaluationInfo> evaluations;
	private List<CustomerServiceInfo> customerServices;

	public double getOriginalCost() {
		return originalCost;
	}

	public void setOriginalCost(double originalCost) {
		this.originalCost = originalCost;
	}

	public double getCurrentCost() {
		return currentCost;
	}

	public void setCurrentCost(double currentCost) {
		this.currentCost = currentCost;
	}

	public double getMarketCost() {
		return marketCost;
	}

	public void setMarketCost(double marketCost) {
		this.marketCost = marketCost;
	}

	public int getSaleNum() {
		return saleNum;
	}

	public void setSaleNum(int saleNum) {
		this.saleNum = saleNum;
	}

	public int getInventoryNum() {
		return inventoryNum;
	}

	public void setInventoryNum(int inventoryNum) {
		this.inventoryNum = inventoryNum;
	}

	public int getShopId() {
		return shopId;
	}

	public void setShopId(int shopId) {
		this.shopId = shopId;
	}

	public int getProductId() {
		return productId;
	}

	public void setProductId(int productId) {
		this.productId = productId;
	}

	public int getCommentsCount() {
		return commentsCount;
	}

	public void setCommentsCount(int commentsCount) {
		this.commentsCount = commentsCount;
	}

	public int getGold() {
		return gold;
	}

	public void setGold(int gold) {
		this.gold = gold;
	}

	public double getGoldToMoneyRatio() {
		return goldToMoneyRatio;
	}

	public void setGoldToMoneyRatio(double goldToMoneyRatio) {
		this.goldToMoneyRatio = goldToMoneyRatio;
	}

	public double getGoldToMoney() {
		return goldToMoney;
	}

	public void setGoldToMoney(double goldToMoney) {
		this.goldToMoney = goldToMoney;
	}

	public String getDeliveryUrl() {
		return deliveryUrl;
	}

	public void setDeliveryUrl(String deliveryUrl) {
		this.deliveryUrl = deliveryUrl;
	}

	public String getProductTitle() {
		return productTitle;
	}

	public void setProductTitle(String productTitle) {
		this.productTitle = productTitle;
	}

	public String getProductName() {
		return productName;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}

	public String getProductIntros() {
		return productIntros;
	}

	public void setProductIntros(String productIntros) {
		this.productIntros = productIntros;
	}

	public String getShopName() {
		return shopName;
	}

	public void setShopName(String shopName) {
		this.shopName = shopName;
	}

	public String getOpenTime() {
		return openTime;
	}

	public void setOpenTime(String openTime) {
		this.openTime = openTime;
	}

	public List<String> getLabels() {
		return labels;
	}

	public void setLabels(List<String> labels) {
		this.labels = labels;
	}

	public List<PictureInfo> getProductPictures() {
		return productPictures;
	}

	public void setProductPictures(List<PictureInfo> productPictures) {
		this.productPictures = productPictures;
	}

	public List<Map<String, String>> getSpecifications() {
		return specifications;
	}

	public void setSpecifications(List<Map<String, String>> specifications) {
		this.specifications = specifications;
	}

	public List<ProductDetailGraphicDetailInfo> getGraphicDetails() {
		return graphicDetails;
	}

	public void setGraphicDetails(List<ProductDetailGraphicDetailInfo> graphicDetails) {
		this.graphicDetails = graphicDetails;
	}   
	

	public List<ProductEvaluationInfo> getEvaluations() {
		return evaluations;
	}

	public void setEvaluations(List<ProductEvaluationInfo> evaluations) {
		this.evaluations = evaluations;
	}

	public List<CustomerServiceInfo> getCustomerServices() {
		return customerServices;
	}

	public void setCustomerServices(List<CustomerServiceInfo> customerServices) {
		this.customerServices = customerServices;
	}
	public int getMsendtime() {
		return msendtime;
	}

	public void setMsendtime(int msendtime) {
		this.msendtime = msendtime;
	}

	public static ProductDetailInfo parse(JSONObject jsonObject) throws JSONException{
		ProductDetailInfo data = new ProductDetailInfo();
		
		if(jsonObject == null){
			return data;
		}
		
		data.evaluations = ProductEvaluationInfo.parse(jsonObject.getJSONArray("pinlun"));
        data.customerServices = CustomerServiceInfo.parse(jsonObject.getJSONArray("CustomerServices"));

		JSONObject detailJsonObject = jsonObject.getJSONObject("details");
		data.shopId = detailJsonObject.getInt("shop_id");
        data.shopName = detailJsonObject.getString("shop_name");
        data.productId = detailJsonObject.getInt("product_id");
        data.productTitle = detailJsonObject.getString("product_title");
        data.productIntros = detailJsonObject.getString("product_intros");
        data.productName = detailJsonObject.getString("product_name");
        data.originalCost = detailJsonObject.getDouble("tag_price");
        data.currentCost = detailJsonObject.getDouble("sale_price");
        data.marketCost = detailJsonObject.getDouble("average_price");
        data.saleNum = detailJsonObject.getInt("sale_num");
        data.inventoryNum = detailJsonObject.getInt("num");
        data.commentsCount = detailJsonObject.getInt("pinglun_num");
        data.gold = detailJsonObject.getInt("gold");
//        data.goldToMoneyRatio = detailJsonObject.getJSONObject("goldInfo").getDouble("1gold2RMB");//一金豆对应的RMB
//        data.goldToMoney = detailJsonObject.getJSONObject("goldInfo").getDouble("gold2money");
        data.deliveryUrl = detailJsonObject.getString("deliveryURL");     
        data.openTime = detailJsonObject.getString("open_time");
        data.msendtime = detailJsonObject.getInt("msendtime");
		data.productPictures = PictureInfo.parse(detailJsonObject.getJSONArray("product_picture"));
		data.graphicDetails = ProductDetailGraphicDetailInfo.parse(detailJsonObject.getJSONArray("extend_intros"));
		
		JSONArray specArr = detailJsonObject.getJSONArray("specifications");
		for(int i = 0; i < specArr.length(); i++) {
			HashMap<String, String> map = new HashMap<String, String>();
			map.put("name", specArr.getJSONObject(i).getString("name"));
			map.put("val", specArr.getJSONObject(i).getString("val"));
			data.specifications.add(map);
		}
        
		JSONArray labelArr = detailJsonObject.getJSONArray("promotion");
		for(int i = 0; i < labelArr.length(); i++) {
			data.labels.add(labelArr.getJSONObject(i).getString("name"));
		}
		
		return data;
	}

}
